package com.shoufeng.client;

import com.shoufeng.grpc.MessageRequest;
import com.shoufeng.grpc.MessageResponse;
import com.shoufeng.grpc.MessageServiceGrpc;
import com.shoufeng.grpc.MessageServiceGrpc.MessageServiceBlockingStub;
import io.grpc.ManagedChannel;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;
import java.io.File;
import javax.net.ssl.SSLException;

public class MessageClient {

  public static void main(String[] args) throws SSLException {
    String url = "127.0.0.1";
    int port = 8080;
    ManagedChannel managedChannel = NettyChannelBuilder.forAddress("localhost", 8080)
        .sslContext(GrpcSslContexts.forClient().trustManager(new File("ssl/ca.crt")).build())
        .build();
    MessageServiceBlockingStub messageServiceBlockingStub = MessageServiceGrpc
        .newBlockingStub(managedChannel);
    MessageResponse messageResponse = messageServiceBlockingStub
        .addMessage(MessageRequest.newBuilder().setMessageId("11").setMessageType("1212").build());
    System.out.println(messageResponse.getMessageId());
  }
}
